<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Registers the script with the SCM, so that it can act as the service with the given name</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.win32-set-service-status.html">win32_set_service_status</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.win32-start-service.html">win32_start_service</a></div>
 <div class="up"><a href="ref.win32service.html">win32service 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.win32-start-service-ctrl-dispatcher" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">win32_start_service_ctrl_dispatcher</h1>
  <p class="verinfo">(PECL win32service SVN)</p><p class="refpurpose"><span class="refname">win32_start_service_ctrl_dispatcher</span> &mdash; <span class="dc-title">Registers the script with the SCM, so that it can act as the service with the given name</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.win32-start-service-ctrl-dispatcher-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>win32_start_service_ctrl_dispatcher</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   )</div>


  <p class="para rdfs-comment">
   When launched via the Service Control Manager, a service process is
   required to &quot;check-in&quot; with it to establish service monitoring and
   communication facilities.  This function performs the check-in by spawning
   a thread to handle the lower-level communication with the service control
   manager.
  </p>
  <p class="para">
   Once started, the service process should do 2 things. The first is to tell
   the Service Control Manager that the service is running. This is achieved
   by calling <span class="function"><a href="function.win32-set-service-status.html" class="function">win32_set_service_status()</a></span> with the
   <strong><code>WIN32_SERVICE_RUNNING</code></strong> constant. If you need to perform
   some lengthy process before the service is actually running, then you can
   use the <strong><code>WIN32_SERVICE_START_PENDING</code></strong> constant. The
   second is to continue to check-in with the service control manager so that
   it can determine if it should terminate. This is achieved by periodically
   calling <span class="function"><a href="function.win32-get-last-control-message.html" class="function">win32_get_last_control_message()</a></span> and handling the
   return code appropriately.
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-function.win32-start-service-ctrl-dispatcher-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">name</code></em></dt>

     <dd>

      <p class="para">
       The short-name of the service, as registered by
       <span class="function"><a href="function.win32-create-service.html" class="function">win32_create_service()</a></span>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.win32-start-service-ctrl-dispatcher-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    成功时返回 <strong><code>TRUE</code></strong>，参数错误时返回 <strong><code>FALSE</code></strong>，或失败时返回一个 <a href="win32service.constants.errors.html" class="link">Win32 错误码</a>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.win32-start-service-ctrl-dispatcher-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5273">
    <p><strong>Example #1 A <span class="function"><strong>win32_start_service_ctrl_dispatcher()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Check if the service is runnig under the SCM.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">win32_start_service_ctrl_dispatcher</span><span style="color: #007700">(</span><span style="color: #DD0000">'dummyphp'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;die(</span><span style="color: #DD0000">"I'm&nbsp;probably&nbsp;not&nbsp;running&nbsp;under&nbsp;the&nbsp;service&nbsp;control&nbsp;manager"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">win32_set_service_status</span><span style="color: #007700">(</span><span style="color: #0000BB">WIN32_SERVICE_START_PENDING</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Some&nbsp;lengthy&nbsp;process&nbsp;to&nbsp;get&nbsp;this&nbsp;service&nbsp;up&nbsp;and&nbsp;running.<br /><br /></span><span style="color: #0000BB">win32_set_service_status</span><span style="color: #007700">(</span><span style="color: #0000BB">WIN32_SERVICE_RUNNING</span><span style="color: #007700">);<br /><br />while&nbsp;(</span><span style="color: #0000BB">WIN32_SERVICE_CONTROL_STOP&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #0000BB">win32_get_last_control_message</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;do&nbsp;some&nbsp;work&nbsp;here,&nbsp;trying&nbsp;not&nbsp;to&nbsp;take&nbsp;more&nbsp;than&nbsp;around&nbsp;30&nbsp;seconds<br />&nbsp;&nbsp;#&nbsp;before&nbsp;coming&nbsp;back&nbsp;into&nbsp;the&nbsp;loop&nbsp;again<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.win32-start-service-ctrl-dispatcher-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.win32-set-service-status.html" class="function" rel="rdfs-seeAlso">win32_set_service_status()</a> - Update the service status</span></li>
    <li class="member"><span class="function"><a href="function.win32-get-last-control-message.html" class="function" rel="rdfs-seeAlso">win32_get_last_control_message()</a> - Returns the last control message that was sent to this service</span></li>
    <li class="member"><a href="win32service.constants.errors.html" class="link">Win32 Error Codes</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.win32-set-service-status.html">win32_set_service_status</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.win32-start-service.html">win32_start_service</a></div>
 <div class="up"><a href="ref.win32service.html">win32service 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
